package com.example.exceldemo.entity;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.format.NumberFormat;
import com.alibaba.excel.annotation.write.style.*;
import lombok.*;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;

/**
 * @Description
 * @Author xiaohuang
 * @Date 2024/7/12
 */

@Data
@HeadRowHeight(30)  //表头行高
@ContentRowHeight(15)  //内容行高
@ColumnWidth(18)  //列宽
//@ContentFontStyle(fontHeightInPoints = (short) 15) //字体大小
@ContentStyle(horizontalAlignment = com.alibaba.excel.enums.poi.HorizontalAlignmentEnum.CENTER) //内容垂直居中
public class Person {
    //index: 列索引(排序), name: 列名
    @ExcelProperty(value = "序号",index = 0)
    private Integer line;
    @ExcelProperty(value = "年龄",index = 2)
    private Integer age;
    @ExcelProperty(value = "姓名",index = 1)
    private String name;
    //设置字体样式：标红
    @ContentFontStyle(color = 10)
    @ExcelProperty(value = "工作",index = 3)
    private String job;
    //将小数转换成百分数,"#.##%",保留两位并四舍五入
    @NumberFormat(value = "0.00%", roundingMode = RoundingMode.HALF_UP)
    @ExcelProperty("百分比%")
    private BigDecimal doubleData;
    @NumberFormat(value = "0.00", roundingMode = RoundingMode.HALF_UP)
    @ExcelProperty("保留两位有效数%")
    @ColumnWidth(25)
    private Double num;
    // 日期格式化格式化
    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
    @ExcelProperty("出生时间")
    @ColumnWidth(25)
    private LocalDateTime date;
    //导出忽略该字段
    @ExcelIgnore
    @ExcelProperty("工龄")
    private Integer workAge;
}
